using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingPanel : BasePanel
{
    [SerializeField] private Button returnButton;

    // [SerializeField] private Slider mainVolume;

    [SerializeField] private Slider BGM;

    [SerializeField] private Slider SFX;

    // [SerializeField] private AudioVolume audioVolume;
    
    
    //
    void Start()
    {
        returnButton.onClick.AddListener(ReturnAction);
        // 
        BGM.onValueChanged.AddListener(delegate { OnSliderBGMValueChanged(); });
        SFX.onValueChanged.AddListener(delegate { OnSliderSFXValueChanged(); });
        BGM.value = AudioVolume.Instance.GetAudioVolumeBGM();
        Camera.main.GetComponent<AudioSource>().volume = BGM.value;
        SFX.value = AudioVolume.Instance.GetAudioVolumeSFX();
    }
    
    //

    private void OnSliderBGMValueChanged()
    {
        AudioVolume.Instance.SetAudioVolumeBGM(BGM.value);
        Camera.main.GetComponent<AudioSource>().volume = BGM.value;
    }

    private void OnSliderSFXValueChanged()
    {
        AudioVolume.Instance.SetAudioVolumeSFX(SFX.value);
    }

    //
    private void ReturnAction()
    {
        UIManager.Instance.ClosePanel(UIConst.PANEL_SETTING);
    }
}
